package main

import (
	"unsafe"
	"fmt"
)

func main() {
	type student struct {
		name string
		age int
	}
	s1 := student{"Adam", 18}
	s1P := &s1
	s1Ptr := uintptr(unsafe.Pointer(s1P))  // 结构体的地址
	fmt.Println(s1Ptr)
	namePtr := s1Ptr + unsafe.Offsetof(s1P.name)  // name属性的地址
	agePtr := s1Ptr + unsafe.Offsetof(s1P.age)  // age属性的地址
	fmt.Println(namePtr, agePtr)
	nameP := (*string)(unsafe.Pointer(namePtr))  // 获取到属性的指针
	ageP := (*int)(unsafe.Pointer(agePtr))
	fmt.Println(*nameP, *ageP)  // 取值获取到属性指针的值
}